<template>
  <div>
    <Layout>
      <Content class="layout-content">
        <div class="card-box" :style="{paddingRight: authorityList.includes('yibaotongji') && authorityList.includes('shebaotongji') ? '90px' : '230px'}">
          
        </div>
        <!--    县级别    -->
        <county :authority-list="authorityList"
                v-if="(authorityList.includes('yibaoyuanxingtu') && authorityList.includes('yibaozhexiantu')) || (authorityList.includes('shebaoyuanxingtu') && authorityList.includes('shebaozhexiantu'))"></county>

        <!--    村级别    -->
        <village :authority-list="authorityList"
                 v-if="!authorityList.includes('yibaozhexiantu') && !authorityList.includes('shebaozhexiantu')"></village>
      </Content>
      <Sider class="layout-sider ml12" hide-trigger width="500">
        <!--    缴费政策    -->
        <div class="card-box" style="height: 268px">
          <div class="flex space-between">
            <div class="card-tit">
              <img src="@/assets/img/home-policy.png" alt="" class="mr6">
              缴费政策
            </div>
            <div class="line20 curPointer" style="color: #1476FD;" @click="goRouter('zhengceguanli')">
              更多
            </div>
          </div>
          <div>
            <a class="list-item" v-for="item in policyData" :key="item.id"
               @click="goRouter('policyDetail','home',{id:item.id})">
              <div class="title" v-html="item.policyTitle"></div>
              <div class="date">{{ parseTime(item.createDate, "{y}-{m}-{d}") }}</div>
            </a>
          </div>
        </div>
        <!--    快捷功能    -->
        <quick-function></quick-function>
        <!--    二维码管理    -->
        <qr-code-management :authority-list="authorityList"></qr-code-management>
      </Sider>
    </Layout>
  </div>
</template>

<script>
import county from "./components/county";
import village from "./components/village";
import quickFunction from "./components/quickFunction";
import qrCodeManagement from "./components/qrCodeManagement";

export default {
  name: "home",
  components: {
    county,  // 县级别统计图
    village,  // 村级别统计图
    quickFunction,  // 快捷功能
    qrCodeManagement,  // 二维码管理
  },
  data() {
    return {
      authorityList: [],
      sheBaoNum: {
        sheBaoTodayAmount: 0,
        sheBaoWeekAmount: 0,
        sheBaoMonthAmount: 0,
        sheBaoYearAmount: 0,
      },  //社保数字统计
      yiBaoNum: {
        yiBaoTodayAmount: 0,
        yiBaoWeekAmount: 0,
        yiBaoMonthAmount: 0,
        yiBaoYearAmount: 0,
      },  //医保数字统计
      policyData: [],  // 政策数据
    };
  },
  watch: {},
  created() {
    let routers = JSON.parse(localStorage.getItem("routers"));
    // 初始化进来，当前菜单不为本页面时，设置为本页面
    if (localStorage.getItem("menus") !== this.$route.name) {
      localStorage.setItem("menus", this.$route.name);
    }
    let menus = localStorage.getItem("menus");
    let currentMenus = routers.find(item => item.name == menus);
    if (currentMenus.children.length) {
      currentMenus = currentMenus.children[0];
    }
    if (currentMenus.children.length) {
      this.authorityList = currentMenus.children.map(item => item.component);
    }

    if (this.authorityList.includes('shebaotongji')) {
      // 社保数字统计
      this.workhomeSheBao();
    }
    if (this.authorityList.includes('yibaotongji')) {
      // 医保数字统计
      this.workhomeYiBao();
    }
    // 缴费政策
    this.policyList();

  },
  mounted() {
  },
  computed: {},
  methods: {
    // 社保数字统计
    workhomeSheBao() {
      this.APIS.workhomeSheBao().then((res) => {
        if (res.code == 20000) {
          this.sheBaoNum = res.data;
        } else {
          this.$Message.error(res.message)
        }
      })
    },
    // 社保数字统计
    workhomeYiBao() {
      this.APIS.workhomeYiBao().then((res) => {
        if (res.code == 20000) {
          this.yiBaoNum = res.data;
        } else {
          this.$Message.error(res.message)
        }
      })
    },
    // 政策列表
    policyList() {
      let data = {
        page: {
          current: 1,
          size: 5,
        },
        categoryId: 1,
      }
      this.APIS.policyList(data).then((res) => {
        if (res.code == 20000) {
          this.policyData = res.data.records;
        } else {
          this.$Message.error(res.message)
        }
      }).catch(err => {
      });
    },

    // 路由跳转
    goRouter(name, menu, query, params) {
      localStorage.setItem("menus", menu ? menu : name);
      this.$router.push({
        name: name,
        query: query,
        params: params
      })
    },
  },
};
</script>

<style lang="less" scoped>
@import "./style.less";
</style>
